package org.aurora.remote.netty;

import org.aurora.remote.RemoteConnectionEventManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public interface NettyEventSubscriber extends RemoteConnectionEventManager<NettyEvent> {
    Logger log = LoggerFactory.getLogger(NettyEventSubscriber.class);

    default void processorEvent(NettyEvent nettyEvent) {
        if (nettyEvent == null) {
            log.warn("NettyEventSubscriber processorEvent is null");
            return;
        }
        NettyEventType nettyEventType = nettyEvent.getType();

        switch (nettyEventType) {
            case CONNECT: {
                this.connect(nettyEvent);
                break;
            }
            case EXCEPTION: {
                this.exception(nettyEvent);
                break;
            }
            case DISCONNECT: {
                this.disconnect(nettyEvent);
                break;
            }
            default: {
                log.error("NettyEventSubscriber processorEvent type is not exist");
            }
        }
    }

    String getSubscriberName();
}
